import java.util.Stack;

public class MinStack {
    Stack<Integer> numStack;
    Stack<Integer> minStack;
    public MinStack() {
        numStack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int x) {
        if (minStack.size()>0){
            if (x>minStack.peek()){
                minStack.push(minStack.peek());
            }else {
                minStack.push(x);
            }
            numStack.push(x);
        }else {
            numStack.push(x);
            minStack.push(x);
        }
    }

    public void pop() {
        numStack.pop();
        minStack.pop();
    }

    public int top() {
        return numStack.peek();
    }

    public int min() {
        return minStack.peek();
    }
}
